package com.hc.sss.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hc.sss.common.ResultMap;
import com.hc.sss.mapper.AdvertisementMapper;
import com.hc.sss.pojo.Advertisement;
import com.hc.sss.service.AdvertisementService;

@Service
public class AdvertisementServiceImpl implements AdvertisementService {

	@Autowired
	AdvertisementMapper advertisementMapper;
	
	//查询所有广告分页
	public ResultMap<Advertisement> findAdvertisementList(Map<String, Object> paramMap) {
		ResultMap<Advertisement> resultMap = new ResultMap<Advertisement>();
		Integer page = 1;
		Integer limit = 5;
		if (paramMap.get("page") != null && !"".equals(paramMap.get("page"))) {
			page = Integer.valueOf(paramMap.get("page").toString());
		}
		if (paramMap.get("limit") != null && !"".equals(paramMap.get("limit"))) {
			limit = Integer.valueOf(paramMap.get("limit").toString());
		}
		PageHelper.startPage(page, limit);
		List<Advertisement> list = advertisementMapper.findAdvertisementList(paramMap);
		PageInfo<Advertisement> info = new PageInfo<>(list);
		resultMap.setData(list);
		resultMap.setCount((int)info.getTotal());
		return resultMap;
	}

	//添加广告
	public int insertAdvertisement(Advertisement advertisement) {
		return advertisementMapper.insertAdvertisement(advertisement);
	}

	//修改删除广告
	public int updateAdvertisement(Advertisement advertisement) {
		return advertisementMapper.updateAdvertisement(advertisement);
	}

}
